package com.tanhua.server.controller;

/**
 * @Author: cl
 * @Date: 2022/5/7 - 05 - 07
 * @Description:
 */

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 环信消息模块
 */
@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 通过环信的id查询用户的信息
     *
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity getUserinfo(String huanxinId) {

        System.out.println(huanxinId + "11111-----------------------------------");
        UserInfoVo vo = messagesService.getUserinfo(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 分页展示好友列表(通过好友名字条件查询)
     *
     * @param page
     * @param pagesize
     * @param keyword
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity getFriend(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "1") Integer pagesize,
                                    String keyword) {

        PageResult pr = messagesService.getFriend(page, pagesize, keyword);
        return ResponseEntity.ok(pr);
    }

    /**
     * 通过用户的id添加好友
     *
     * @param map
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {

        String str = map.get("userId").toString();

        System.out.println(str + "222------------------------------------");
        Long userId = Long.valueOf(str);//被添加人的id

        messagesService.contacts(userId);
        return ResponseEntity.ok("添加成功");
    }

    /**
     * 点赞列表
     *
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity likes(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {

        PageResult pr = messagesService.likes(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 评论列表
     *
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity comments(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {

        PageResult pr = messagesService.comments(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 喜欢列表
     *
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity loves(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {

        PageResult pr = messagesService.loves(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 公告
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {

        List<Announcements> list = new ArrayList();
        list.add(new Announcements());
        new PageResult(page, pagesize, 0l, list);
        PageResult pr = messagesService.loves(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    @Data
    class Announcements {
        private String id = "121";
        private String title = "探花新版本上线发布啦～,盛夏high趴开始了，赶紧来报名吧！";
        private String description = "探花App2019年7月23日起在苹果商店…,浓情夏日，清爽一聚，探花将吧大家聚…";
        private String createDate = "2019-09-08 10:07";
    }

}
